package com.xjy.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.FundLedger;
import com.xjy.system.domain.bo.FundLedgerQueryBo;
import com.xjy.system.domain.vo.FundLedgerVo;
import com.xjy.system.mapper.FundLedgerMapper;
import com.xjy.system.service.IFundLedgerService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 资金流水总账Service业务层处理
 *
 * @author mlb
 * @date 2022-03-20
 */
@Service
public class FundLedgerServiceImpl extends ServicePlusImpl<FundLedgerMapper, FundLedger> implements IFundLedgerService {

    @Override
    public FundLedgerVo queryById(Long projId){
        return getVoById(projId, FundLedgerVo.class);
    }

    @Override
    public TableDataInfo<FundLedgerVo> queryPageList(FundLedgerQueryBo bo) {
        PagePlus<FundLedger, FundLedgerVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), FundLedgerVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<FundLedgerVo> queryList(FundLedgerQueryBo bo) {
        return listVo(buildQueryWrapper(bo), FundLedgerVo.class);
    }

    private LambdaQueryWrapper<FundLedger> buildQueryWrapper(FundLedgerQueryBo bo) {
		Map<String, Object> params = bo.getParams();
		LambdaQueryWrapper<FundLedger> lqw = Wrappers.lambdaQuery();
		lqw.between(params.get("beginDate") != null && params.get("endDate") != null,
			FundLedger::getDate ,params.get("beginDate"), params.get("endDate"));
		lqw.like(StrUtil.isNotBlank(bo.getName()), FundLedger::getName, bo.getName());
		lqw.like(StrUtil.isNotBlank(bo.getAccountName()), FundLedger::getAccountName, bo.getAccountName());
		return lqw;
    }


}
